package my.video.lib.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JCheckBox;

import my.video.lib.controller.Controller;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

public class PreferencesDialog extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel buttonPane;
	@SuppressWarnings("unused")
	private Controller controller;
	private PreferencesDialog preferencesDialog;
	private JButton saveButton;
	private JButton cancelButton;

	/**
	 * Create the dialog.
	 * @param controller 
	 */
	public PreferencesDialog(final Controller controller) {
		this.controller = controller;
		this.preferencesDialog = this;
		setTitle("Einstellungen");
		setBounds(100, 100, 498, 332);
		{
			buttonPane = new JPanel();
			{
				saveButton = new JButton("Speichern");
				saveButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						controller.saveButtonActionPerformed(evt, preferencesDialog);
					}
				});
				getRootPane().setDefaultButton(saveButton);
			}
			{
				cancelButton = new JButton("Abbrechen");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						controller.cancelButtonActionPerformed(evt, preferencesDialog);
					}
				});
			}
		}
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Auswahl der Dateitypen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(10)
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
					.addGap(10))
				.addComponent(buttonPane, GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
					.addComponent(buttonPane, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		GroupLayout gl_buttonPane = new GroupLayout(buttonPane);
		gl_buttonPane.setHorizontalGroup(
			gl_buttonPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_buttonPane.createSequentialGroup()
					.addGap(278)
					.addComponent(saveButton)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(cancelButton)
					.addGap(34))
		);
		gl_buttonPane.setVerticalGroup(
			gl_buttonPane.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_buttonPane.createSequentialGroup()
					.addContainerGap(20, Short.MAX_VALUE)
					.addGroup(gl_buttonPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(cancelButton)
						.addComponent(saveButton))
					.addContainerGap())
		);
		buttonPane.setLayout(gl_buttonPane);
		
		
		JCheckBox prefCheckboxAvi = new JCheckBox("AVI", controller.getBooleanProperty("AVI"));
		prefCheckboxAvi.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent evt) {
				controller.checkBoxItemStateChanged(evt);
			}
		});
		
		JCheckBox prefCheckboxMkv = new JCheckBox("MKV", controller.getBooleanProperty("MKV"));
		prefCheckboxMkv.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent evt) {
				controller.checkBoxItemStateChanged(evt);
			}
		});
		
		JCheckBox prefCheckboxWmv = new JCheckBox("WMV", controller.getBooleanProperty("WMV"));
		prefCheckboxWmv.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent evt) {
				controller.checkBoxItemStateChanged(evt);
			}
		});
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
						.addComponent(prefCheckboxWmv, GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
						.addComponent(prefCheckboxMkv, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(prefCheckboxAvi, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
					.addContainerGap(337, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(prefCheckboxAvi)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(prefCheckboxMkv)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(prefCheckboxWmv)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
		getContentPane().setLayout(groupLayout);
	}
}
